package com.becca.cake.model.goods;

import java.io.Serializable;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import com.becca.cake.core.exception.ServiceException;

/**
 * 配件实体类
 * @copyright  尊星(上海)信息科技有限公司
 * @author 
 * @date 2016年6月13日 下午5:57:29
 */
public class GoodsFixingModel implements Serializable {
    /**  */
    private static final long  serialVersionUID       = 1L;
    private Integer            id;
    /**配件名称*/
    private String             fixingName;
    /**配件编码*/
    private String             fixingCode;
    /**配件展示图*/
    private String             fixingPicture;
    /**配件单价*/
    private Double             fixingPrice;
    /**配件单位*/
    private String             fixingUnits;
    /**配件描述*/
    private String             describes;
    /**是否可选*/
    private Byte               isOptional;
    /**选择框最大选择范围值*/
    private Integer            optionalRange;
    /**是否可用*/
    private Byte               isEnable;
    /**排序*/
    private Integer            sort;
    /**创建时间*/
    private Date               createdDate;
    /**创建人*/
    private String             createdName;
    /**修改时间*/
    private Date               updatedDate;
    /**修改人*/
    private String             updatedName;

    /**配件单位倍数*/
    private Integer            fixingMultiple;
    /**配件类型*/
    private Byte               fixingType;

    /**配件类型(1:赠送配件)*/
    public static final Byte   FIXING_TYPE_GIVE              = 1;
   
    /**可用*/
    public static final Byte   IS_ENABLE              = 0;

    /**不可用*/
    public static final Byte   IS_NOT_ENABLE          = 1;

    /**可选*/
    public static final Byte   IS_OPTIONAL            = 0;

    /**不可选*/
    public static final Byte   IS_NOT_OPTIONAL        = 1;

    /**配件信息为空*/
    public static final String FIXING_NULL            = "配件信息不能为空";
    /**配件名称不能为空*/
    public static final String FIXING_NAME_NULL       = "配件名称不能为空";
    /**配件价格需大于0*/
    public static final String FIXING_PRICE_ZERO      = "配件价格需大于0";
    /**配件单位不能为空*/
    public static final String FIXING_UNITS_NULL      = "配件单位不能为空";
    /**配件是否可选不能为空*/
    public static final String FIXING_ISOPTIONAL_NULL = "配件是否可选不能为空";
    /**配件排序不能为空*/
    public static final String FIXING_SORT_NULL       = "配件排序不能为空";
    /**配件类型不能为空*/
    public static final String FIXING_TYPE_NULL       = "配件类型不能为空";
    /**该配件已设置为可用*/
    public static final String FIXING_ENABLE_EXIST      = "该配件已设置为可用";
    /**该配件设置为不可用*/
    public static final String FIXING_NOT_ENABLE_EXIST      = "该配件设置为不可用";
    /**配件ID不能为空*/
    public static final String FIXING_ID_NULL      = "配件ID不能为空";
    /**该配件已被启用*/
    public static final String FIXING_IS_ENABLE_USER      = "该配件已被启用";
    /**该配件已被启用*/
    public static final String FIXING_IS_ENABLE_FORBIDDEN     = "该配件已被启用";
    

    /**
     * 商品配件是否为空校验
     * @param goodsFixingModel
     * @param files
     */
    public static void validInsertOrUpdateFixing(GoodsFixingModel goodsFixingModel,
                                                 MultipartFile files) {
        if (goodsFixingModel == null) {
            throw new ServiceException(GoodsFixingModel.FIXING_NULL);
        }
        if (StringUtils.isEmpty(goodsFixingModel.getFixingName())) {
            throw new ServiceException(GoodsFixingModel.FIXING_NAME_NULL);
        }
        if (StringUtils.isEmpty(goodsFixingModel.getFixingUnits())) {
            throw new ServiceException(GoodsFixingModel.FIXING_UNITS_NULL);
        }
        if (goodsFixingModel.getIsOptional() == null) {
            throw new ServiceException(GoodsFixingModel.FIXING_ISOPTIONAL_NULL);
        }
        if (goodsFixingModel.getSort() == null) {
            throw new ServiceException(GoodsFixingModel.FIXING_SORT_NULL);
        }
        if (goodsFixingModel.getId() == null && files.isEmpty()) {
            throw new ServiceException(GoodsPictureModel.PICTURE_UPDLOAD_FAILED);
        }
        if(goodsFixingModel.getFixingType() == null){
            throw new ServiceException(GoodsFixingModel.FIXING_TYPE_NULL);
        }
        if(goodsFixingModel.getFixingType() == 0 && goodsFixingModel.getFixingPrice() == 0){
            throw new ServiceException(GoodsFixingModel.FIXING_PRICE_ZERO);
        }
    }
    
    /**
     * 校验配件id是否为空
     * @param fixingId
     */
    public static void validfixingIdIsNull(Integer fixingId){
        if(fixingId == null){
            throw new ServiceException(GoodsFixingModel.FIXING_ID_NULL);
        }
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFixingName() {
        return fixingName;
    }

    public void setFixingName(String fixingName) {
        this.fixingName = fixingName;
    }

    public String getFixingPicture() {
        return fixingPicture;
    }

    public void setFixingPicture(String fixingPicture) {
        this.fixingPicture = fixingPicture;
    }

    public Double getFixingPrice() {
        return fixingPrice;
    }

    public void setFixingPrice(Double fixingPrice) {
        this.fixingPrice = fixingPrice;
    }

    public String getFixingUnits() {
        return fixingUnits;
    }

    public void setFixingUnits(String fixingUnits) {
        this.fixingUnits = fixingUnits;
    }

    public String getDescribes() {
        return describes;
    }

    public void setDescribes(String describes) {
        this.describes = describes;
    }

    public Byte getIsOptional() {
        return isOptional;
    }

    public void setIsOptional(Byte isOptional) {
        this.isOptional = isOptional;
    }

    public Integer getOptionalRange() {
        return optionalRange;
    }

    public void setOptionalRange(Integer optionalRange) {
        this.optionalRange = optionalRange;
    }

    public String getFixingCode() {
        return fixingCode;
    }

    public void setFixingCode(String fixingCode) {
        this.fixingCode = fixingCode;
    }

    public Byte getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(Byte isEnable) {
        this.isEnable = isEnable;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getCreatedName() {
        return createdName;
    }

    public void setCreatedName(String createdName) {
        this.createdName = createdName;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getUpdatedName() {
        return updatedName;
    }

    public void setUpdatedName(String updatedName) {
        this.updatedName = updatedName;
    }

    public Integer getFixingMultiple() {
        return fixingMultiple;
    }

    public void setFixingMultiple(Integer fixingMultiple) {
        this.fixingMultiple = fixingMultiple;
    }

    public Byte getFixingType() {
        return fixingType;
    }

    public void setFixingType(Byte fixingType) {
        this.fixingType = fixingType;
    }
    
}
